package logic

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"user_srv/model"
	"user_srv/proto"
)

// 获取用户信息
func (s *Server) GetUserByMobile(ctx context.Context, in *proto.GetUserByMobileRequest) (*proto.GetUserByMobileResponse, error) {
	mobile, err := model.GetUserByMobile(in.Mobile)
	if err != nil {
		return nil, status.Error(codes.Internal, "获取用户信息失败")
	}
	if mobile.ID == 0 {
		return nil, status.Error(codes.Internal, "用户不存在")
	}
	return &proto.GetUserByMobileResponse{
		Id:       int64(mobile.ID),
		Mobile:   mobile.Mobile,
		Password: mobile.Password,
		NickName: mobile.NickName,
		Sex:      int64(mobile.Sex),
		Age:      int64(mobile.Age),
	}, nil
}
